package com.diankangwo.api.config;

import com.diankangwo.api.interceptor.AuthorizationInterceptor;
import com.diankangwo.api.resolver.LoginUserHandlerMethodArgumentResolver;
import com.diankangwo.factory.interceptor.AuthorizationInterceptor2;
import com.diankangwo.factory.resolver.LoginUserHandlerMethodArgumentResolver2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/** MVC配置
 * Created by wuye on 2017/9/5.
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private AuthorizationInterceptor authorizationInterceptor;
    @Autowired
    private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver;

    @Autowired
    private AuthorizationInterceptor2 authorizationInterceptor2;
    @Autowired
    private LoginUserHandlerMethodArgumentResolver2 loginUserHandlerMethodArgumentResolver2;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authorizationInterceptor).addPathPatterns("/api/**");
        registry.addInterceptor(authorizationInterceptor2).addPathPatterns("/fac/**");
        registry.addInterceptor(authorizationInterceptor2).addPathPatterns("/fac/fac/**");
        registry.addInterceptor(authorizationInterceptor2).addPathPatterns("/sys/user/save");
        registry.addInterceptor(authorizationInterceptor2).addPathPatterns("/fac/commodity/save");
        registry.addInterceptor(authorizationInterceptor2).addPathPatterns("/fac/order/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(loginUserHandlerMethodArgumentResolver);
        argumentResolvers.add(loginUserHandlerMethodArgumentResolver2);
    }


}
